<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::any('test_d', function () {
    $res = request('data');
    if(!is_array($res))
        $res = json_decode($res,true);
    foreach ($res as $k=>$v) {
//        echo $v['text'];
//        echo count($v['children']);
//        die;
        saveP($v);
    }
    echo json_encode($res);
});

Route::any('test_excel', function () {
    $data = [
        'sn'=>'货号',
        'title'=>'名称',
        'abstract'=>'简介',
        'length'=>'长',
        'wide'=>'宽',
        'gram_weight'=>'克重',
        'price'=>'价格',
        'texture'=>'材质(用,隔开)',
        'technology'=>'工艺(用,隔开)',
        'labels'=>'标签(用,隔开)',
        'sort'=>'排序(越小越前)',
    ];
    $_c_Array = ['分类'];
    $c_r = app()->build(\App\Repositories\CategoryRepository::class);
    $ar = $c_r->getLevelData();
    foreach ($ar as $v) {
        $_c_Array[$v->id] = $v->parent->title.'-'.$v->title;
    }
    $data['category_id'] = $_c_Array;

    \App\ZL\ORG\Excel\ExcelHelper::templateExport($data,'商品模版');
});

Route::any('inport_excel', function () {
    return view('inport_excel');
});

Route::any('share', function () {
    return view('share');
});

Route::any('color_test', function () {
    $files = scandir('../colors');
    $files = \Illuminate\Support\Facades\Storage::disk('public')->files('colors');
    dd($files);
    foreach ($files as $file) {
        if ($file != '.' && $file != '..') {
            if (is_dir($path . '/' . $file)) {
                scanFile($path . '/' . $file);
            } else {
                $result[] = basename($file);
            }
        }
    }
});

Route::any('init', function () {
    \Illuminate\Support\Facades\DB::table('goods')->truncate();
    \Illuminate\Support\Facades\DB::table('goods_color')->truncate();
    \Illuminate\Support\Facades\DB::table('goods_product')->truncate();
    \Illuminate\Support\Facades\DB::table('goods_slideshows')->truncate();
    \Illuminate\Support\Facades\DB::table('goods_article')->truncate();
});

Route::get('test', function () {
//    $user = \App\User::find(1);
    $res = sendVerifyCode(13867558443,22);
    dd($res);
    die;
    return view('configs.test');
});
Route::get('/', function () {
    return redirect(route('admin.index'));
});

Route::post('post_excel', 'Admin\GoodsController@postExcel');

Auth::routes();

Route::group(['middleware' => 'home.checkwechatlogin','namespace' => 'Home'], function () {});

Route::group(['middleware' => 'auth.admin:admin','namespace' => 'Admin','prefix' => 'admin'], function () {

    Route::get('/', 'HomeController@index')->name('admin.index');
    Route::get('/users', 'UserController@index')->name('users.index');
    Route::get('/users/{id}', 'UserController@edit')->name('users.edit');
    Route::patch('/users/{id}', 'UserController@update')->name('users.update');

    Route::get('/value_edit/{type}', 'ConfigController@valueEdit')->name('configs.value_edit');
    Route::any('/value_update/{type}', 'ConfigController@valueUpdate')->name('configs.value_update');

    Route::post('/delpic','GoodsController@delpic');

    Route::resource('categories', 'CategoryController');
    Route::resource('configs', 'ConfigController');
    Route::resource('colors', 'ColorController');
    Route::resource('articles', 'ArticleController');
    Route::resource('categories', 'CategoryController');
    Route::resource('labels', 'LabelController');
    Route::resource('goods', 'GoodsController');
    Route::resource('indexSlideshows', 'IndexSlideshowController');
    Route::resource('orders', 'OrderController');
    Route::resource('newDevelopments', 'NewDevelopmentController');
    Route::resource('newDevelopmentTypes', 'NewDevelopmentTypeController');
    Route::resource('roles', 'RoleController');
});
//Route::get('/home', 'Admin\HomeController@index')->name('admin.home');
